package zzz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import zzz.mapper.ReplyMapper;
import zzz.mapper.UserMapper;
import zzz.model.Reply;
import zzz.model.User;
import zzz.service.ReplyService;

@Service
@Transactional
public class ReplyServiceImpl implements ReplyService{

	@Autowired
	private ReplyMapper mapper;
	@Autowired
	private UserMapper umapper;
	
	@Override
	public int replyPost(Reply reply) {
		// TODO Auto-generated method stub
		int i=mapper.addReply(reply);
		return i;
	}

	@Override
	public List<Reply> findReplyByPost(String postId) {
		// TODO Auto-generated method stub
		List<Reply> replys=mapper.findReplyByPost(postId);
		for(int i=0;i<replys.size();i++){
			Reply r=replys.get(i);
			User u=umapper.getUserById(String.valueOf(r.getUserId()));
			r.setUser(u);
		}
		return replys;
	}

}
